package com.pro.db.service;

import com.pro.db.dao.BbsSiteMapper;
import com.pro.db.domain.BbsForum;
import com.pro.db.dao.BbsForumMapper;
import com.pro.db.domain.BbsSite;
import com.pro.db.service.itf.IBbsForumService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 板块表 服务实现类
 * </p>
 *
 * @author wanglei
 * @since 2020-01-07
 */
@Service
public class BbsForumServiceImpl extends ServiceImpl<BbsForumMapper, BbsForum> implements IBbsForumService {

    @Autowired
    BbsForumMapper forumMapper;

    @Autowired
    BbsSiteMapper siteMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveForum(BbsForum bbsForum) {
        forumMapper.insert(bbsForum);

        BbsSite bbsSite = siteMapper.selectById(bbsForum.getSiteId());
        BbsSite update = new BbsSite();
        update.setId(bbsSite.getId());
        update.setForumNum(bbsSite.getForumNum()+1);
        siteMapper.updateById(update);
    }
}
